package com.example.design.core;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 文件匹配器工具类
 */
public final class FileMatchers {

    private FileMatchers() {}

    public static FileMatcher byExtension(String... exts) {
        final Set<String> s = Arrays.stream(exts)
                .map(String::toLowerCase)
                .collect(Collectors.toSet());
        return (file, name, ext) -> ext != null && s.contains(ext.toLowerCase());
    }

    public static FileMatcher byPrefix(String prefix) {
        return (file, name, ext) -> name != null && name.startsWith(prefix);
    }

    public static FileMatcher and(FileMatcher... matchers) {
        return (file, name, ext) -> Arrays.stream(matchers).allMatch(m -> m.matches(file, name, ext));
    }
}
